#!/usr/bin/env python
# -*- coding:utf-8 -*-
import t1
import wx
import sys

class myFrame(t1.MyFrame1):
    def __init__(self, parent):
        t1.MyFrame1.__init__(self, parent)
        self.sk = "N/A"
        self.ttk = "N/A"
        self.ttf = "N/A"
        self.jc = "N/A"

    def calc_proc( self, event ):
        gw = float(self.m_textCtrl2.GetValue())
        gh = float(self.m_textCtrl3.GetValue())
        err_msg = ""
        (gw_er, gh_er) = self.sk_type(gw, gh)
        if gw_er + gh_er == 0:
            (gw_er, gh_er) = self.ttj_value(gw, gh)
            if gw_er + gh_er > 0:
                if gw_er > 0:
                    err_msg = err_msg + "管道外径输入有误" + "\n"
                if gh_er > 0:
                    err_msg = err_msg + "管道壁厚输入有误"
        else:
            if gw_er > 0:
                err_msg = err_msg + "管道外径输入有误" + "\n"
            if gh_er > 0:
                err_msg = err_msg + "管道壁厚输入有误"
        self.m_grid1.SetCellValue(0,0,self.sk)
        self.m_grid1.SetCellValue(0, 1, self.ttk)
        self.m_grid1.SetCellValue(0, 2, self.ttf)
        self.m_grid1.SetCellValue(0, 3, self.jc)
        self.m_staticText3.SetLabelText(err_msg)


    def ttj_value(self, gw, gh):
        gw_er = 0
        gh_er = 0
        if 32 <= gw < 159:
            if 4 <= gh <= 8:
                self.ttk = "2.5-3.0"
                self.ttf = "4.0-5.0"
                self.jc = "Φ2×20-24dB"
            elif 8 < gh <= 15:
                self.ttk = "2.0-2.5"
                self.ttf = "4.0-5.0"
                self.jc = "Φ2×20-20dB"
            elif gh > 15:
                self.ttk = "1.5-2.0"
                self.ttf = "2.0-2.5"
                self.jc = "Φ2×20-16dB"
            else:
                gh_er = 1
                # self.ttk = "N/A"
                # self.ttf = "N/A"
                # self.jc = "N/A"
        elif 159 <= gw <500:
            if 6 <= gh <= 25:
                self.ttk = "2.0-3.0"
                self.ttf = "2.0-5.0"
                self.jc = "Φ2×40-18dB"
            elif 25 < gh <= 40:
                self.ttk = "1.5-2.5"
                self.ttf = "2.0-5.0"
                self.jc = "Φ2×40-18dB"
            elif gh > 40:
                self.ttk = "1.0-2.0"
                self.ttf = "2.0-2.5"
                self.jc = "Φ2×60-14dB"
            else:
                gh_er = 1
                # self.ttk = "N/A"
                # self.ttf = "N/A"
                # self.jc = "N/A"
        elif gw >= 500:
            if 6 <= gh <= 25:
                self.ttk = "2.0-3.0"
                self.ttf = "4.0-5.0"
                self.jc = "Φ2×40-18dB"
            elif 25 < gh <= 40:
                self.ttk = "1.5-2.5"
                self.ttf = "2.0-5.0"
                self.jc = "Φ2×40-18dB"
            elif gh > 40:
                self.ttk = "1.0-2.0"
                self.ttf = "2.0-2.5"
                self.jc = "Φ2×60-14dB"
            else:
                gh_er = 1
                # self.ttk = "N/A"
                # self.ttf = "N/A"
                # self.jc = "N/A"
        else:
            gw_er = 1
            # self.ttk = "N/A"
            # self.ttf = "N/A"
            # self.jc = "N/A"
        return (gw_er, gh_er)
    def sk_type(self, gw, gh):
        # gw = float(self.m_textCtrl2.GetValue())
        # gh = float(self.m_textCtrl3.GetValue())
        gw_er = 0
        gh_er = 0
        if 32 <= gw < 159:
            if gh <= 4 or gh >= 50:
                # self.sk = "N/A"
                gh_er = 1
            else:
                if 32 <= gw < 48:
                    self.sk = "GS-1"
                elif 48 <= gw < 72:
                    self.sk = "GS-2"
                elif 72 <= gw < 110:
                    self.sk = "GS-3"
                else:
                    self.sk = "GS-4"
        elif 159 <= gw < 500:
            if gh < 6 or gh > 50:
                # self.sk = "N/A"
                gh_er = 1
            else:
                if 6 <= gh <= 10:
                    self.sk = "CSK-ⅠA, RB-C-1"
                elif 10 < gh <= 16:
                    self.sk = "CSK-ⅠA, RB-C-2"
                elif 16 < gh <= 24:
                    self.sk = "CSK-ⅠA, RB-C-3"
                elif 24 < gh <= 36:
                    self.sk = "CSK-ⅠA, RB-C-4"
                elif 36 < gh <= 50:
                    self.sk = "CSK-ⅠA, RB-C-5"
        elif gw >=500:
            if gh < 6 or gh >150:
                # self.sk = "N/A"
                gh_er = 1
            else:
                self.sk = "CSK-ⅠA、CSK-ⅡA"
        else:
            gw_er = 1
            # self.sk = "N/A"
        return ( gw_er, gh_er)

if __name__ == "__main__":
    app = wx.App(False)
    frame = myFrame(None)
    frame.Show(True)
    app.MainLoop()